class Forum < ActiveRecord::Base
  acts_as_list :scope => :category
  belongs_to :category
  has_many :topics, :order => 'topics.replied_at DESC'
  belongs_to :last_reply, :foreign_key => 'last_reply_id', :class_name => 'Post'
  belongs_to :last_reply_in_topic, :foreign_key => 'last_reply_in', :class_name => 'Topic'
  
  validates_presence_of :name
  validates_presence_of :category_id
  validates_presence_of :position
  
  def before_create
    self.permalink = self.name.to_permalink if self.permalink.blank?
  end
  
  def to_param
    "#{id}-#{permalink}"
  end
end
